Ext.namespace("Despatch");

Despatch.View = function(p) {
	this.parentWin=p;	
	
	this.hdManagerId = new Ext.form.Hidden({name:'managerId'});
	this.storeYear=new Ext.data.ArrayStore({
	        	fields: ['value', 'name'],
	        	data: OMS.DEPT_YEAR
	    });	
	this.cbYear = new Ext.form.ComboBox({
		width: 100,
		name:'planYear',
		fieldLabel: '年份',
		store:this.storeYear ,
		valueField: 'value',
        displayField: 'name',
        editable: false,
        disabled:true,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.storeMonth= new Ext.data.ArrayStore({
	        	fields: ['value', 'name'],
	        	data: OMS.DEPT_MONTH
	    });
	this.cbMonth = new Ext.form.ComboBox({
		width: 100,
		name:'planMonth',
		fieldLabel: '月份',
		store:this.storeMonth,
		valueField: 'value',
        displayField: 'name',
        editable: false,
        disabled:true,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.hdParBranchId = new Ext.form.Hidden({name:'parBranchId'});
	this.txtParBranch = new Ext.form.TextField({
		width: 100,
		fieldLabel: '区域',
		name:'parBranchName',
		disabled:true
	});
	
    this.hdBranchId = new Ext.form.Hidden({name:'branchId'});
	this.txtBranch = new Ext.form.TextField({
		width: 100,
		fieldLabel: '营业厅',
		name:'branchName',
		disabled:true
	});
	this.form = new Ext.FormPanel({
		bodyStyle: 'padding: 5px 5px 0',
        labelWidth: 70,
        labelAlign: 'right',
        items: [{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .50, items: [this.cbYear]},
	        	         { columnWidth: .50, items: [this.cbMonth]}]
	    				},{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .50, items: [this.txtParBranch]},
	        	         { columnWidth: .50, items: [this.txtBranch]}]
	    	},this.hdManagerId,this.hdParBranchId,this.hdBranchId]
    });
    
    this.fileForm = new Ext.FormPanel({
        bodyStyle: 'padding: 5px 5px 0',
        labelWidth: 70,
        labelAlign: 'right',
        fileUpload: true, 
        items: []
	});
    Despatch.View.superclass.constructor.call(this, {
		title: '查看排班表',
        autoHeight: false,
        width: 500,
        y: 20,
        resizable: false,
        plain: true,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items: [this.form,this.fileForm],
        buttons: [{
            text: '关闭',
            scope: this,
            handler: function() {
	        	this.hide();
        	}
        }],
        buttonAlign:'center'
	});
};
Ext.extend(Despatch.View, Ext.Window, {
	initWin:function(data){
		//alert(Ext.util.JSON.encode(data));
		if(data){
			this.form.getForm().setValues(data);
			this.initFile(data);
		}		
	},
	initFile:function(o){
		this.fileForm.removeAll(true);
		var conn = new Ext.data.Connection({
			url:'../despatchManager/searchUpLoadFiles.form?timesnap=' + Date.parse(new Date()),
			method:'post'
		})
		Utils.request(conn,{
			params:{managerId:o.managerId},
			scope:this,
			success:function(data){
				var files=data.result;
				for(var i=0;i<files.length;i++){
					this.scope.addFile(files[i]);
				}
			}
		});
	},
	addFile:function(o){
		var href='../despatchManager/downloadFile.form?fileId='+o.ACCESSORY_ID+'&timesnap=' + Date.parse(new Date());
		var lbLink=new Ext.form.Label({
			html:'<a href="'+href+'">'+o.ACCESSORY_NAME+'</>    ',
			width:280
		});
		this.fileForm.add(lbLink);
	    this.fileForm.doLayout();   
	}
});
